package com.zeroxml.cms.web.action.cms;

import net.sourceforge.stripes.integration.spring.SpringBean;
import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.action.UrlBinding;
import com.zeroxml.cms.service.IArticleService;
import com.zeroxml.cms.service.ICatalogService;
import com.zeroxml.cms.service.ICommentService;
import com.zeroxml.cms.service.ILinkService;
import com.zeroxml.cms.bo.Article;
import com.zeroxml.cms.bo.Catalog;
import com.zeroxml.cms.bo.Link;
import com.zeroxml.cms.bo.Comment;
import com.zeroxml.cms.web.action.BaseAction;
import com.wyvoid.core.persistent.hibernate.HibernatePage;

import java.util.List;

/**
 * User: cjp
 * Date: 2007-9-16
 * Time: 21:51:33
 */
@UrlBinding("/java.do")
public class JavaAction extends BaseAction {
    @SpringBean
    IArticleService articleService;
    @SpringBean
    ICatalogService catalogService;
    @SpringBean
    private ICommentService commentService;
    @SpringBean
    private ILinkService linkService;

    HibernatePage<Article> articles;
    private int curPage;
    private List<Link> links;
    private List<Comment> latestComments;
    private List<Article> recommedArticles;

    public void setArticleService(IArticleService articleService) {
        this.articleService = articleService;
    }

    public void setCatalogService(ICatalogService catalogService) {
        this.catalogService = catalogService;
    }

    public void setCommentService(ICommentService commentService) {
        this.commentService = commentService;
    }

    public void setLinkService(ILinkService linkService) {
        this.linkService = linkService;
    }

    public HibernatePage<Article> getArticles() {
        return articles;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
    }


    public List<Link> getLinks() {
        return links;
    }

    public List<Comment> getLatestComments() {
        return latestComments;
    }

    public List<Article> getRecommedArticles() {
        return recommedArticles;
    }

    @DefaultHandler
    public Resolution java() {
        Catalog catalog = catalogService.getCatalog("java");
        if (catalog != null) {
            int pageSize = 20;
            articles = articleService.findArticles(catalog.getId(), null, curPage, pageSize);
            links = linkService.getIndexLinks(5);
            latestComments = commentService.getLatestComments(20);
            recommedArticles = articleService.getRecommedArticles(catalog.getId());
        }

        return getCmsResolution("java/java");
    }
}
